package edu.rutgers.moko;

import java.util.Date;
import java.util.Timer;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;

import edu.rutgers.moko.data.MyTask;

/**
 * 
 * @author Darja Krushevskaja
 * 
 */
public class App {
	public static void main(String[] args) {
		App app = new App();
		try {
			app.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void start() throws Exception {
		MyTask task = new MyTask(1000);
		Timer timer = new Timer();
		timer.scheduleAtFixedRate(task, new Date(), 10000);

		Server server = new Server(8080);
		Context root = new Context(server, "/", Context.SESSIONS);
		root.addServlet(new ServletHolder(new StateServlet()), "/state/*");
		root.addServlet(new ServletHolder(new RssServlet(task)), "/rss/*");
		root.addServlet(new ServletHolder(new MessageServlet()), "/msg/*");
		root.addServlet(new ServletHolder(new SequrityControlServlet()), "/scs/*");

		server.start();
		server.join();

	}
}
